﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chbl.DAL;
using Chbl.Models;

namespace Chbl.Controllers
{
    public class ScheduleController : Controller
    {
        private readonly ChblDb _db;

        public ScheduleController(ChblDb chblDb)
        {
            _db = chblDb;
        }
        //
        // GET: /Schedule/

        public ActionResult Index(int seasonDivisionId)
        {
            var model = GetGamesSchedule(_db, seasonDivisionId);

            return View(model);
        }

        public static IOrderedQueryable<Game> GetGamesSchedule(ChblDb db, int seasonDivisionId)
        {
            return db.Games.Include(g => g.HomeTeam).Include(g => g.RoadTeam).Include(g => g.SeasonDivision)
                .Where(g => g.SeasonDivisionId == seasonDivisionId)
                .OrderBy(g => g.TourNumber)
                .ThenBy(g => g.GameOrder);
        }

        //
        // GET: /Schedule/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Schedule/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Schedule/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Schedule/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Schedule/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Schedule/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Schedule/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
